using Microsoft.EntityFrameworkCore;
using WMS.RealTime.Domain.Entities;

namespace WMS.RealTime.Infrastructure
{
    public class RealTimeDbContext : DbContext
    {
        public RealTimeDbContext(DbContextOptions<RealTimeDbContext> options) : base(options)
        {
        }

        public DbSet<DashboardData> DashboardData { get; set; }
        public DbSet<SystemMessage> SystemMessages { get; set; }
        public DbSet<AlertInfo> AlertInfos { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            // DashboardData配置
            modelBuilder.Entity<DashboardData>(entity =>
            {
                entity.HasKey(e => e.Id);
                entity.Property(e => e.DataType).IsRequired().HasMaxLength(50);
                entity.Property(e => e.JsonData).IsRequired();
                entity.Property(e => e.CreatedTime).IsRequired();
                entity.HasIndex(e => e.DataType);
            });

            // SystemMessage配置
            modelBuilder.Entity<SystemMessage>(entity =>
            {
                entity.HasKey(e => e.Id);
                entity.Property(e => e.Title).IsRequired().HasMaxLength(200);
                entity.Property(e => e.Content).IsRequired();
                entity.Property(e => e.MessageType).IsRequired().HasMaxLength(20);
                entity.Property(e => e.CreatedTime).IsRequired();
                entity.HasIndex(e => e.CreatedTime);
            });

            // AlertInfo配置
            modelBuilder.Entity<AlertInfo>(entity =>
            {
                entity.HasKey(e => e.Id);
                entity.Property(e => e.AlertType).IsRequired().HasMaxLength(50);
                entity.Property(e => e.Title).IsRequired().HasMaxLength(200);
                entity.Property(e => e.Description).IsRequired();
                entity.Property(e => e.Severity).IsRequired().HasMaxLength(20);
                entity.Property(e => e.CreatedTime).IsRequired();
                entity.HasIndex(e => e.AlertType);
                entity.HasIndex(e => e.IsResolved);
            });
        }
    }
} 